﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using W7Toshil.Entity;
using System.IO.IsolatedStorage;
using W7Toshil.Services;

namespace W7Toshil
{
    public partial class AddExpenses : PhoneApplicationPage
    {
        public AddExpenses()
        {
            InitializeComponent();
        }

        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            decimal amount ;
            Expense expense = new Expense()
            {
                 Date = string.IsNullOrEmpty(this.DateTextBox.Text) ? DateTime.Now  : Convert.ToDateTime(DateTextBox.Text) ,
                 Amount = decimal.TryParse(this.AmountTextBox.Text,out  amount) ? amount : default(decimal),
                 TagName = string.IsNullOrEmpty(this.TaggingTextBox.Text) ? "Default" : this.TaggingTextBox.Text 
            };

            ITransaction<Expense> expenseService = new ExpenseTransaction();
            expenseService.Add(expense);

            Reset();



        }

        private void ClearButton_Click(object sender, RoutedEventArgs e)
        {
            Reset();
            
        }

        private void Reset()
        {
            this.AmountTextBox.Text = string.Empty;
            this.DateTextBox.Text = string.Empty;
            this.TaggingTextBox.Text = string.Empty;
        }
    }
}